package com.example.thymeleaf.dao.impl;

import com.example.thymeleaf.bean.User;
import com.example.thymeleaf.dao.UserDao;

import java.util.List;

/**
 * @author ddone
 * @date 2024/3/13-12:36
 */
public class UserDaoImpl extends BaseDaoImpl implements UserDao {
    @Override
    public List<User> findUserList() {
        String sql = "select * from user";
       return this.getList(User.class, sql);
    }

    @Override
    public int insertUser(User user) {
        String sql = "INSERT INTO user(username, pwd, email) VALUES(?,?,?)";
        return this.update(sql, user.getUsername(), user.getPwd(), user.getEmail());
    }

    @Override
    public User findUserById(int userid) {
        String sql = "select * from user where userid=?";
        return this.getBean(User.class,sql,userid);
    }

    @Override
    public int updateUser(User user) {
        String sql = "update user set username=?,pwd=?,email=? where userid=?";
        return this.update(sql,user.getUsername(),user.getPwd(),user.getEmail(),user.getUserid());
    }

    @Override
    public int deleteById(int userid) {
        String sql = "delete from user where userid=?";
        return this.update(sql,userid);
    }
}
